package com.duan.laugh.event.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.duan.laugh.event.mapper.EventNoticeMapper;
import com.duan.laugh.event.pojo.entity.EventNotice;
import com.duan.laugh.event.service.IEventNoticeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 事件通知 服务实现类
 * </p>
 *
 * @author liutf
 * @since 2019-11-12
 */
@Service
public class EventNoticeServiceImpl extends ServiceImpl<EventNoticeMapper, EventNotice> implements IEventNoticeService {

    /**
     * 0010406 根据事件处理规则id查询事件通知
     *
     * @param id
     * @return
     */
    @Override
    public List<EventNotice> selectListByEventHandlerRuleId(String id) {
        return super.list(new LambdaQueryWrapper<EventNotice>().eq(EventNotice::getEventHandlerRuleId, id));
    }

    /**
     * 0010407 根据事件处理规则ids批量删除事件通知
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteByEventHandlerRuleIds(String ids) {
        List<String> strings = StrUtil.split(ids, ',', -1);
        return super.remove(new LambdaQueryWrapper<EventNotice>().in(EventNotice::getEventHandlerRuleId, strings));
    }
}
